Skip to content

Add documentation on top of rustc_middle/src/query/mod.rs #142450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xizheyin
Copy link
Contributor

The rustc-dev-guide gives a high-level intro, but many details—especially about how the code works and modifiers in query xxx(){...}—are only in code comments or the macro implementation. This doc makes it easier for contributors and code readers to understand the workflow and available modifiers without jumping between files and docs.

This PR adds a comprehensive module-level doc comment to rustc_middle::query::mod.rs that:

  1. Provides an overview of the query system and macro-based query definitions for reading code more easily
  2. Centralizes documentation for all query modifiers (previously scattered or only in rustc_macro code), closely following the authoritative list in QueryModifiers.

@rustbot
Copy link
Collaborator

rustbot commented Jun 13, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 13, 2025
Copy link
Member

@SparrowLii SparrowLii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, thanks!

@xizheyin xizheyin force-pushed the rustc-query-doc branch 2 times, most recently from 7b757e3 to a7220f3 Compare June 13, 2025 13:31
Comment on lines 8 to 22
//! ## How to Read This Module
//!
//! Each `query` block in this file defines a single query, specifying its key and value types, along with various modifiers.
//! These query definitions are processed by the macro system, which expands them into the necessary boilerplate code
//! for the query system—including the [`Providers`] struct (a function table for all query implementations, where each field is
//! a function pointer to the actual provider), caching, and dependency graph integration.
//! **Note:** The `Providers` struct is not a Rust trait, but a struct generated by the macro system to hold all provider functions.
//! The macro system also supports a set of **query modifiers** (see below) that control the behavior of each query.
//!
//! The actual provider functions are implemented in various modules and registered into the `Providers` struct
//! during compiler initialization (see [`rustc_interface::passes::DEFAULT_QUERY_PROVIDERS`]).
//!
//! [`rustc_interface::passes::DEFAULT_QUERY_PROVIDERS`]: ../../rustc_interface/passes/static.DEFAULT_QUERY_PROVIDERS.html
//!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restructured it to focus on interpreting the code, focusing on the core structure of Providers, which is a good place to start in understanding this module.

Copy link
Member

@SparrowLii SparrowLii Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustc macros is better than macro systems here. Others looks fine.

@rustbot rustbot added the A-rustc-dev-guide Area: rustc-dev-guide label Jun 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 13, 2025

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol

@SparrowLii
Copy link
Member

r=me after fixing the nits
@bors delegate+

@bors
Copy link
Collaborator

bors commented Jun 16, 2025

✌️ @xizheyin, you can now approve this pull request!

If @SparrowLii told you to "r=me" after making some further change, please make that change, then do @bors r=@SparrowLii

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
@xizheyin
Copy link
Contributor Author

CI has passed.
@bors r=@SparrowLii

@bors
Copy link
Collaborator

bors commented Jun 16, 2025

📌 Commit ade2ad9 has been approved by SparrowLii

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 16, 2025
Kobzol added a commit to Kobzol/rust that referenced this pull request Jun 16, 2025
…wLii

Add documentation on top of `rustc_middle/src/query/mod.rs`

The `rustc-dev-guide` gives a high-level intro, but many details—especially about how the code works and modifiers in `query xxx(){...}`—are only in code comments or the macro implementation. This doc makes it easier for contributors and code readers to understand the workflow and available modifiers without jumping between files and docs.

This PR adds a comprehensive module-level doc comment to `rustc_middle::query::mod.rs` that:
1. Provides an overview of the query system and macro-based query definitions for reading code more easily
2. Centralizes documentation for all query modifiers (previously scattered or only in `rustc_macro` code), closely following the authoritative list in QueryModifiers.
bors added a commit that referenced this pull request Jun 16, 2025
Rollup of 12 pull requests

Successful merges:

 - #141639 (Expose discriminant values in stable_mir)
 - #142082 (Refactor `rustc_attr_data_structures` documentation)
 - #142125 (Stabilize "file_lock" feature)
 - #142236 (Add documentation for `PathBuf`'s `FromIterator` and `Extend` impls)
 - #142373 (Fix Debug for Location)
 - #142416 (Assorted bootstrap cleanups (step 2))
 - #142431 (Add initial version of snapshot tests to bootstrap)
 - #142450 (Add documentation on top of `rustc_middle/src/query/mod.rs`)
 - #142528 (clarify `rustc_do_not_const_check` comment)
 - #142530 (use `if let` guards where possible)
 - #142561 (Remove an `njn:` comment accidentaly left behind.)
 - #142566 (Fix `-nopt` CI jobs)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustc-dev-guide Area: rustc-dev-guide S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants